//
//  BSNavigationViewController.m
//  sister
//
//  Created by 周冰烽 on 2017/2/13.
//  Copyright © 2017年 周冰烽. All rights reserved.
//

#import "BSNavigationViewController.h"

@interface BSNavigationViewController ()

@end

@implementation BSNavigationViewController

+(void)initialize{
    //当导航栏用在BSNavigationController中,设置才会其效果
    UINavigationBar *bar = [UINavigationBar appearanceWhenContainedInInstancesOfClasses:@[[self class]]];
    [bar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackgroundWhiter"] forBarMetrics:UIBarMetricsDefault];
}


- (void)viewDidLoad {
    [super viewDidLoad];

}

/**
 可以在这个方法中拦截所有push进来的控制器
 */
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    if (self.childViewControllers.count > 0) {//如果push进来的不是第一个控制器
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"返回" forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
        button.size = CGSizeMake(70, 30);
        //设置按钮里面内容向左靠
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        //设置按钮向左缩进10
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:button];
        //跳转隐藏tabbar
        viewController.hidesBottomBarWhenPushed = YES;
    }
    //super的push一定要放在后面,让ViewController可以覆盖上面设置的leftBarButtonItem
    [super pushViewController:viewController animated:animated];
}
-(void)back{
    [self popViewControllerAnimated:YES];
}










@end
